// 动态规划
var coinChange = function(coins, amount) {
    if (amount === 0) return 0;
    let dp = [];
    for (let i = 0; i <= amount; i++) {
      dp[i] = amount + 1;
    }
    dp[0] = 0;
    for (let i = 0; i <= amount; i++) {
      for (let j = 0; j < coins.length; j++) {
        if (i >= coins[j]) {
          dp[i] = Math.min(dp[i - coins[j]] + 1, dp[i])
        }
      }
    }
    return dp[amount] === amount + 1 ? -1 : dp[amount];
  };